package com.sczmgk.hotline_pzh.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.sczmgk.hotline_pzh.MyApp;
import com.sczmgk.hotline_pzh.R;
import com.sczmgk.hotline_pzh.base.BaseActivity;
import com.sczmgk.hotline_pzh.callback.SimplePaserJsonCallback;
import com.sczmgk.hotline_pzh.constants.Constants;
import com.sczmgk.hotline_pzh.dialog.DialogFactory;
import com.sczmgk.hotline_pzh.entity.ComplainInfo;
import com.sczmgk.hotline_pzh.entity.StepDetailBean;
import com.sczmgk.hotline_pzh.entity.StepInfo;
import com.sczmgk.hotline_pzh.httputils.MyHttp;
import com.sczmgk.hotline_pzh.sp.CacheUtils;
import com.sczmgk.hotline_pzh.utils.CommonUtils;
import com.sczmgk.hotline_pzh.view.MyGridView;

import java.util.HashMap;
import java.util.Map;

public class StepDetailActivity extends BaseActivity {
    /*处理意见的内容*/
    private TextView mTvContent;

    /*处理意见的标题*/
    private TextView mTvTile;

    /*处理意见的相关文件以及容器*/
    private MyGridView mFileGridView;
    private LinearLayout mFileGrideViewContainer;

    /*去评价的按钮*/
    private Button mBtnGoEvalute;
    private StepInfo currentStepInfo;
    private ComplainInfo complaintInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_opinion);

        //将activity添加到集合中
        CommonUtils.addActivity(this);

        initData() ;

        setHeader() ;

        initView() ;

        setListener() ;
    }

    /**
     * 设置头
     */
    private void setHeader() {
        setTitle(R.string.complaint_step_detail);
        setLeftBtnVisibility(View.VISIBLE);
    }

    /**
     * 初始化控件
     */
    private void initView() {

        //标题和内容
        mTvTile = (TextView) findViewById(R.id.tv_opinion_title);
        mTvContent = (TextView) findViewById(R.id.tv_opinion_content);

        //相关文件的控件和容器
        mFileGridView = (MyGridView) findViewById(R.id.gv_file);
        mFileGrideViewContainer = (LinearLayout) findViewById(R.id.ll_file_gridview_container);

        //去评价的按钮
        mBtnGoEvalute = (Button) findViewById(R.id.btn_go_evalute);
        mBtnGoEvalute.setVisibility(View.GONE);

    }

    /**
     * 初始化数据
     */
    private void initData() {

        //获取传递的投诉id
        Intent intent = getIntent() ;
        currentStepInfo = (StepInfo) intent.getSerializableExtra(Constants.COMOLAIN_STEP_INFO_KEY);
        complaintInfo = (ComplainInfo) intent.getSerializableExtra(Constants.COMPLAIN_INFO_KEY);
        loadingDialog = DialogFactory.getLoadingDialog(StepDetailActivity.this);
        DialogFactory.showDialog(loadingDialog);
        Map<String,Object> maps = new HashMap<>();
        maps.put("userid", CacheUtils.getIntData(StepDetailActivity.this, Constants.LOGIN_UID,0));
        maps.put("stepid",currentStepInfo.stepid);
        maps.put("imei", MyApp.imei);
        MyHttp.requestByCommon(Constants.BASE_URL + Constants.GET_STEP_DETAILS, maps, MyHttp.GET, StepDetailActivity.this, false, null, new SimplePaserJsonCallback() {
            @Override
            public void onVerifyIsNull() {
                DialogFactory.dismissLoadingDialog(loadingDialog);

            }

            @Override
            public void onVerifySuccess(String dataRaw, boolean isCache) {
                DialogFactory.dismissLoadingDialog(loadingDialog);
                Gson gson = new Gson();
                final StepDetailBean opinionBean = gson.fromJson(dataRaw, StepDetailBean.class);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mTvContent.setText(opinionBean.remark);
                    }
                });
            }
        });

    }

    /**
     * 设置监听
     */
    private void setListener() {
        //去评价的监听
        //去评价的监听
        mBtnGoEvalute.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(StepDetailActivity.this , ComplaintEvaluteActivity.class);
                intent.putExtra(Constants.COMPLAIN_INFO_KEY,complaintInfo);
                startActivity(intent);
            }
        });

    }

    @Override
    public void handleMessage(Message msg) {

    }

    @Override
    public boolean getIsNeedLogin() {
        return true;
    }
}
